package soap.utils;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Component;
import soap.manager.PicxxImgUrlManager;
import soap.pojo.PicxxImgUrl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ZhangPY on 2021/11/19
 * Belong Organization OVERUN-9299
 * overun9299@163.com
 * Explain: PicxxImageUtils
 */

@Component
public class PicxxImageUtils {




    public static void main(String[] args) throws IOException {

        List<PicxxImgUrl> picxxImgUrlList = new ArrayList<>();

        for (int i =1 ;i<202 ;i++) {
            String url = "https://*****.icu/page/"+i;
            PicxxImageUtils.test(url , picxxImgUrlList);
        }



    }

    public static void  test(String url , List<PicxxImgUrl> picxxImgUrlList)  {


        try {
            Document parse = Jsoup.connect(url).ignoreContentType(true).userAgent("Mozilla/5.0 (Windows NT 5.1; zh-CN) AppleWebKit/535.12 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/535.12").timeout(600000).get();

            Elements elementsByClass = parse.getElementsByClass("attachment-full size-full wp-post-image");
            for (Element byClass : elementsByClass) {
                String attr = byClass.getElementsByTag("img").attr("src");
                PicxxImgUrl picxxImgUrl = new PicxxImgUrl();
                picxxImgUrl.setImgUrl(attr);
                picxxImgUrlList.add(picxxImgUrl);
                // I:\noreal\picter
                HttpUtil.downloadFile(attr , FileUtil.file("i:\\noreal\\picter"));
//                System.out.println(attr);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }




}
